package org.lanqiao.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.myUtils.Myutils;
import org.lanqiao.service.FactoryService;

public class TeaSelCoSevelet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int sel=Myutils.getInt(request.getParameter("sel"));
		if(sel==1){
			//获取老师的id
			String teaId=request.getParameter("teaId");
			request.getSession().setAttribute("teacherId", teaId);
			//查询老师未选择的课程
			List tsc=FactoryService.getUserInfoManageService().getOtherCou();
			//获取返回的学生的信息的List的长度
			int otherAC=tsc.size();
			//把这个长度放进缓存
			request.getSession().setAttribute("otherAC", otherAC);
			
			request.getSession().setAttribute("teaSel", tsc);
			//获取当前这个老师选择了的课程
			List nowTeaCou=FactoryService.getUserInfoManageService().getNowTeaCourse(teaId);
			
			request.getSession().setAttribute("nowTeaCou", nowTeaCou);
			request.getRequestDispatcher("logined/UserInfoManager/teaSelectCourse.jsp").forward(request, response);
			
		}else if(sel==2){
			//获取老师的id
			String teaId=(String) request.getSession().getAttribute("teacherId");
			//获取该课程id
			String couId=request.getParameter("courseid");
			//获取该课程的名称
			String couName=request.getParameter("coursename");
			
			List tos=FactoryService.getUserInfoManageService().getAOtherCou(couId,couName,teaId);
			
			request.getSession().setAttribute("teaSel", tos);
			
			List nowTeaCou=FactoryService.getUserInfoManageService().getNowTeaCourse(teaId);
			
			request.getSession().setAttribute("nowTeaCou", nowTeaCou);			
			request.getRequestDispatcher("logined/UserInfoManager/teaSelectCourse.jsp").forward(request, response);

			
		}
		
		
	}
	

}
